
package Szadoban;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class LoginFrame extends JFrame implements ActionListener {
	JPanel panel;
	JList list;
	DefaultListModel model;
	JScrollPane pane;
	JButton chooseBut;
	JButton cancelBut;

	public LoginFrame() {
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(270, 210);
		this.setLocationRelativeTo(null);
		this.setTitle("Login");
		panel = new JPanel();
		panel.setSize(260, 200);
		panel.setLayout(new BorderLayout());
		model = new DefaultListModel();
		list = new JList(model);
		pane = new JScrollPane(list);
		chooseBut = new JButton("Choose");
		cancelBut = new JButton("Cancel");
		
		for (int i = 0; i < Menu.UserList.size(); i++)
			model.addElement(Menu.UserList.get(i).name);
		
		
		
		this.add(panel);
		panel.add(pane, BorderLayout.NORTH);
		panel.add(chooseBut, BorderLayout.WEST);
		panel.add(cancelBut, BorderLayout.EAST);
		this.setVisible(true);
		
		chooseBut.addActionListener(this);
		cancelBut.addActionListener(this);

		
	}
	
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		Object source=e.getSource();
		
		if(source==chooseBut)
		{
			this.dispose();
			GameWindow gamewindow = new GameWindow();
		}
		
		if (source==cancelBut)
		{
			this.dispose();	
			Menu logmenu = new Menu();
			logmenu.remove(logmenu.c1);
			logmenu.setContentPane(logmenu.c2);
			logmenu.validate();
			logmenu.repaint();
		}
		
	
	}

	public static void main(String s[]) {
	LoginFrame Log=new LoginFrame();
	}
}
